import { ref } from 'vue'

export function useImageLoader() {
  const imageErrors = ref({})
  
  const handleImageError = (event, item) => {
    event.target.style.display = 'none'
    imageErrors.value[item.id] = true
  }

  const preloadImages = (images) => {
    images.forEach(img => {
      const image = new Image()
      image.src = img.startsWith('http') ? img : `/uploads/${img}`
    })
  }

  return {
    imageErrors,
    handleImageError,
    preloadImages
  }
} 